<?php
// +----------------------------------------------------------------------
// | astp [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author 荒年 < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 创建自定义菜单
// +----------------------------------------------------------------------
namespace app\wewhat\controller;

use think\Controller;
use app\wewhat\service\HttpRequest;
use app\wewhat\service\Accesstoken;

class Menulst extends Controller
{
  public function lst(){
    return view();
  }
  
  //创建自定义菜单
  public function createMenu()
  {
    $this->delMenu();
    $arr = [
      'button' => [
        [
          'type' => 'click',
          'name' => '音乐',
          'key' => 'key001'
        ],
        [
          'name' => '二级菜单',
          'sub_button' => [
            [
              'type' => 'view',
              'name' => '汇潮',
              'url' => 'http://www.cfckck.com'
            ],
            [
              'type' => 'view',
              'name' => '百度',
              'url' => 'http://www.baidu.com'
            ]
          ],
        ],
        [
          'type' => 'click',
          'name' => '音乐',
          'key' => 'key002'
        ]
      ]
    ];
    $menu = json_encode($arr,256);
    $http = new HttpRequest();
    $access = new Accesstoken();
    $url =  'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$access->getAccessToken();
    $json = $http->http_request($url,$menu);
    return $json;
  }

  // 删除自定义菜单
  public function delMenu()
  {
    $http = new HttpRequest();
    $access = new Accesstoken();
    $url = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token='.$access->getAccessToken();
    $json = $http->http_request($url);
    return $json;
  }

}
?>